console.log("13PointSimplifier");
let utils = data["utils"];
let RBushItem = data["RBushItem"];
let RBU = data["RBU"];
let RBush = data["RBush"];
let AreaForRender = data["AreaForRender"];
let quickselect = data["quickselect"];
let SphericalMercator = data["SphericalMercator"];
let PointItem = data["PointItem"];
let PointForRender = data["PointForRender"];
let BoundsItem = data["BoundsItem"];
let QuadTree = data["QuadTree"];
let Node = data["Node"];
let PointSimplifier = data["PointSimplifier"];
let BaseRender = data["BaseRender"];
let LeftNumFunnel = data["LeftNumFunnel"];

utils.extend(PointSimplifier.prototype, {
  getAvoidPointsByCenter: function (currentCenterLng, currentCenterLat, zoom, width, height) {
    var extent = this.getExtent(currentCenterLng, currentCenterLat, zoom, width, height);
    var avoidPoints = this.getAvoidPoints(extent[0], extent[1], extent[2], extent[3], zoom, width, height);
    return avoidPoints;
  },
  getExtent: function (currentCenterLng, currentCenterLat, zoom, width, height) {
    function scale(a) {
      return 256 * Math.pow(2, a)
    }

    function px2lonlat(mapWidth, mapHeight, centerX, centerY, zoom, targetX, targetY) {
      var result = {
        x: 0,
        y: 0
      }
      var worldWidth = scale(zoom);
      var resoultion66 = (20037508.34 * 2 / worldWidth);

      var centerMec = lonLat2Mercator(centerX, centerY);

      var centerPX = mapWidth / 2;
      var centerPY = mapHeight / 2;
      var dx = (targetX - centerPX) * resoultion66;
      var dy = (targetY - centerPY) * resoultion66;


      var targetLonlat = Mercator2lonLat(centerMec[0] + dx, centerMec[1] - dy);

      result.x = targetLonlat[0];
      result.y = targetLonlat[1];

      return result;
    }

    function lonLat2Mercator(lon, lat) {
      var x = lon * 20037508.34 / 180;
      var y = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
      y = y * 20037508.34 / 180;
      return [x, y];
    }

    function Mercator2lonLat(x, y) {
      var lon = (x / 20037508.34) * 180;
      var lat = (y / 20037508.34) * 180;
      lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
      return [lon, lat];
    }

    var minXY = px2lonlat(width, height, currentCenterLng, currentCenterLat, zoom,
      0, height);

    var maxXY = px2lonlat(width, height, currentCenterLng, currentCenterLat, zoom,
      width, 0);
    var extent = [minXY.x, minXY.y, maxXY.x, maxXY.y]
    return extent;
  },
  getPointsByExtent(min_lng, min_lat, max_lng, max_lat, curZoom, width, height) {
    var avoidPoints = [];
    this.renderEngine.refreshViewState(min_lng, min_lat, max_lng, max_lat, curZoom, width, height);
    this.renderEngine.render();
    avoidPoints = this.renderEngine.curExtentPoints;
    return avoidPoints;
  },
  getPointsByCenter: function (currentCenterLng, currentCenterLat, zoom, width, height) {
    var extent = this.getExtent(currentCenterLng, currentCenterLat, zoom, width, height);
    // var avoidPoints = this.getPointsByExtent(extent[0], extent[1], extent[2], extent[3], zoom, width, height);
    // 根据范围快速过滤数据，简单粗暴类型筛选 20万左右的
    var avoidPoints = [];
    var source = this._data.source;
    for (let index = 0; index < source.length; index++) {
      const element = source[index];
      var lng = element.lng;
      var lat = element.lat;
      if (lng > extent[0] && lng < extent[2] & lat > extent[1] & lat < extent[3]) {
        avoidPoints.push(element);
      }
    }
    return avoidPoints;
  }
});

return {
  "utils": utils,
  "RBushItem": RBushItem,
  "RBU": RBU,
  "RBush": RBush,
  "AreaForRender": AreaForRender,
  "LeftNumFunnel": LeftNumFunnel,
  "quickselect": quickselect,
  "SphericalMercator": SphericalMercator,
  "PointItem": PointItem,
  "PointForRender": PointForRender,
  "BoundsItem": BoundsItem,
  "QuadTree": QuadTree,
  "Node": Node,
  "PointSimplifier": PointSimplifier,
  "BaseRender": BaseRender
}